home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / prg_gen / euphor14.zip / POLYGON.EX < prev    next >
Text File  |  1995-10-18  |  2KB  |  92 lines

  1.         -----------------------------
  2.         -- Polygon Pattern Program --
  3.         -----------------------------
  4.  
  5. -- press space bar to see a new pattern
  6. -- press any other key to quit
  7.  
  8. constant GRAPHICS_MODE = 261 -- SVGA, if this fails try mode 18 
  9.                  -- see also euphoria\include\graphics.e
  10. without type_check
  11.  
  12. include graphics.e
  13. include select.e
  14.  
  15. constant TRUE = 1
  16.  
  17. constant X = 1,
  18.      Y = 2
  19.  
  20. sequence config
  21. integer nlines, npoints, spacing, solid
  22.  
  23. function poly_pattern()
  24.     integer color, color_step, ncolors, key
  25.     sequence points, deltas, history
  26.  
  27.     config = video_config()
  28.     ncolors = config[VC_NCOLORS]
  29.     color = 1
  30.     color_step = 1
  31.     points = rand(repeat(config[VC_XPIXELS..VC_YPIXELS], npoints)) - 1
  32.     deltas = rand(repeat({2*spacing-1, 2*spacing-1}, npoints)) - spacing
  33.     history = {}
  34.     clear_screen()
  35.     while TRUE do
  36.     if length(history) >= nlines then
  37.         -- blank out oldest line
  38.         polygon(0, solid, history[1])
  39.         history = history[2..nlines]
  40.     end if
  41.     polygon(color, solid, points)
  42.     history = append(history, points)
  43.     points = points + deltas
  44.     -- make vertices change direction at edge of screen
  45.     for j = 1 to npoints do
  46.         if points[j][X] <= 0 or points[j][X] >= config[VC_XPIXELS] then
  47.         deltas[j][X] = -deltas[j][X]
  48.         end if
  49.         if points[j][Y] <= 0 or points[j][Y] >= config[VC_YPIXELS] then
  50.         deltas[j][Y] = -deltas[j][Y]
  51.         end if
  52.     end for
  53.     -- step through the colors
  54.     color = color + color_step
  55.     if color >= ncolors then
  56.         color_step = rand(ncolors)
  57.         color = color_step
  58.     end if
  59.     -- change background color once in a while
  60.     if rand(100) = 1 then
  61.         bk_color(rand(ncolors)-1)
  62.     end if
  63.     -- see if user wants to quit
  64.     key = get_key()
  65.     if key = ' ' then
  66.         return 0
  67.     elsif key != -1 then
  68.         return 1
  69.     end if
  70.     end while
  71. end function
  72.  
  73. if not select_mode(GRAPHICS_MODE) then
  74.     puts(1, "couldn't find a good graphics mode\n")
  75.     abort(1)
  76. end if
  77.  
  78. while TRUE do
  79.     -- Play with these parameters for neat effects!
  80.     nlines = 1+rand(140)   -- number of lines on screen at one time
  81.     npoints = 2+rand(16)   -- number of points in polygons
  82.     spacing = 1+rand(24)   -- spacing between lines
  83.     solid = rand(2)-1      -- solid polygons? 1 or 0
  84.     if poly_pattern() then
  85.     exit
  86.     end if
  87. end while
  88.  
  89. if graphics_mode(-1) then
  90. end if
  91.  
  92.